local js_chuanxin = fk.CreateSkill {
  name = "js__chuanxin",
}

js_chuanxin:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and not (player:isNude() and #player:getHandlyIds(false) == 0)
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "#js__chuanxin_viewas", "#js__chuanxin-invoke", true)
    if success then
      event:setCostData(self,dat)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk.skills["#js__chuanxin_viewas"]:viewAs(event:getCostData(self).cards)
    local n = 0
    room.logic:getEventsOfScope(GameEvent.Recover, 999, function(e)
      local recover = e.data
      for _, id in ipairs(event:getCostData(self).targets) do
        if recover.who.id == id then
          n = n + recover.num
        end
      end
    end, Player.HistoryTurn)
    local use = {
      from = player,
      tos = table.map(event:getCostData(self).targets, function(id) return room:getPlayerById(id) end),
      card = card,
      extraUse = true,
      additionalDamage = n,
    }
    room:useCard(use)
  end,
})

return js_chuanxin